This disclosure relates generally to the field of computer graphics. More particularly, but not by way of limitation, it relates to technique for manipulating textures in a rendering system for use with a graphics processing unit (GPU).
A texture is a two-dimensional (2D) image that may be mapped onto a 2D or 3D surface and integrated into a larger scene. Textures may be created from any source, including pre-rendered imagery, dynamic 3D graphics, vector art, and even text. As GPUs have become more prevalent, libraries of textures and graphic processing routines have been developed to provide a rendering system that allows for the use of the power of GPUs for faster rendering of graphics—rather than depending entirely on the processing power of common central processing units (CPUs). Generally, both CPUs and GPUs are involved in graphics processing operations involving mapped textures, with much of the graphics processing being handled by the GPUs.
Groups of textures to be used in a particular application may also be stored in what is known as a “texture atlas,” in order to increase memory efficiency and performance of the application. A texture atlas is simply a large image containing a collection of smaller sub-images, e.g., textures, which may be “trimmed” (e.g., trimmed of superfluous transparent padding pixels) and then placed closely together with adjacent textures. The resulting texture atlas may contain many smaller sub-images, each of which may be used as a texture for some part of a 2D or 3D object to be rendered in the particular application. The individual textures may then be rendered by specifying the texture coordinates of the individual texture in the atlas to point to the particular part of the large image where the individual texture that the application is attempting to render is located. In an application where many small textures are used frequently, it is often more efficient to store the textures in a single texture atlas, which may be treated as a single unit by the graphics hardware, resulting in fewer texture bindings.
One texel (i.e., texture element) of a texture may cover more or less than one pixel in the ultimate display space, so the texel values in the texture may be averaged to produce the final output pixel values for the display space. For example, if the GPU is attempting to draw a texture smaller or larger than its “actual” size in texture atlas (and it's not being drawn larger or smaller by a factor of 2), or if the texture has been rotated, or if the texture is moving across a screen and falls halfway across a pixel, it may result in undesirable visible “seams” between the textures in the display space.
When a GPU is being used to draw a single texture, the developer may also specify a “wrap mode” for the edges of a texture. For example, one option for wrapping is referred to herein as “clamp” mode. Clamp mode simply repeats the value of the edge pixel of the texture for one additional pixel out from the existing edge of the texture. Another option for wrapping is referred to herein as “wrap” mode, which would instead average the edge pixel with the value of the pixel on the opposite side of the texture. This way, when the texture is filtered for tiled display in the ultimate display space, there are no transparent or semi-transparent seams between the tiled textures. Other times, when a developer desires to have smooth, i.e., anti-aliased edges, he or she may specify to draw the texture with a “linear” interpolation mode, which can smoothly interpolate between the pixels abutting the would-be seam region for the pixels located in the would-be seam.
Unfortunately, when generating a texture atlas (i.e., the single large image comprised of many smaller individual sub-textures), the hardware may not be able to determine where the edges of each individual sub-texture are. Further, it is not possible to specify multiple interpolation modes for the various sub-textures that will be stored inside the texture atlas, so these approaches can no longer be used. What is needed are techniques to intelligently analyze and modify incoming textures as they are placed into the texture atlas by a developer so that the textures will be perceptually equivalent when they're drawn in the ultimate display space, even in tiled fashion.